package com.joinway.framework.core.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import com.joinway.framework.core.plugin.PluginAdaptor;
import com.joinway.framework.core.repository.SystemConfigRepository;

@Service
public class WebExceptionService extends PluginAdaptor implements IWebExceptionService {

	private final static Logger log = LoggerFactory.getLogger(WebExceptionService.class);
	
	@Autowired SystemConfigRepository repository;
	
	@Override
	public ModelAndView getErrorPage() {
		return new ModelAndView("redirect:error" + getPageSuffix());
	}

	@Override
	public ModelAndView getIndexPage() {
		return new ModelAndView("redirect:index" + getPageSuffix());
	}

    protected String getPageSuffix(){
    	String suffix = ".dox";
    	
		try {
			suffix = repository.getStringValue(SystemConfigRepository.PageRequestSuffix);
		} catch (Exception e) {
			log.error("Error when get page suffix config", e);
		}
    	
    	return suffix;
    }

}
